import java.util.Arrays;

public class Solution985 {
    public int[] sumEvenAfterQueries(int[] nums, int[][] queries) {
        int sum=0;
        for (int num : nums) {
            if (num%2==0){
                sum+=num;
            }
        }
        int[] ans=new int[queries.length];
        for (int i=0;i<queries.length;i++){
            if (nums[queries[i][1]]%2==0){
                if (queries[i][0]%2==0){
                    sum+=queries[i][0];
                }else {
                    sum-=nums[queries[i][1]];
                }
            }else {
                if (queries[i][0]%2!=0){
                    sum+=queries[i][0]+nums[queries[i][1]];
                }
            }
            nums[queries[i][1]]+=queries[i][0];
            ans[i]=sum;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution985().sumEvenAfterQueries(new int[]{1, 2, 3, 4}, new int[][]{{1, 0}, {-3, 1}, {-4, 0}, {2, 3}})));
    }
}
